/* 
 * @Title: SearchOrderController.java 
 * @Package com.jiankangjin.transsystem.controller 
 * @Description: TODO 
 * @author neason
 * @date 2014年8月13日 上午9:19:35 
 * @version V1.0   
 */ 
package com.jiankangjin.transsystem.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jiankangjin.transsystem.search.DataBaseMap;
import com.jiankangjin.transsystem.search.SearchOrderIds;
import com.jiankangjin.transsystem.services.SearchOrderServices;

/**  
 * 交易查询，返回查询结果记录数，以及缓存结果编号
 */
@Controller
public class SearchOrderController {
	private static final transient Log logger = LogFactory.getLog(SearchOrderController.class);
	
	@Autowired
	private SearchOrderServices searchOrderServices;
	
	/**
	 * 交易查询，返回查询结果记录数，以及缓存结果编号
	 */
	@RequestMapping(value="/search_order",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> searchOrder(
			@RequestParam(required = false) String order_id,
			@RequestParam(required = false) String order_date_begin,
			@RequestParam(required = false) String order_date_end,
			@RequestParam(required = false) String refund_date_begin,
			@RequestParam(required = false) String refund_date_end,
			@RequestParam(required = false) String search_word,
			@RequestParam(required = false) String order_stat,
			@RequestParam(required = false) String isTip,
			@RequestParam(required = false) String sign
			){
		StringBuilder sb = new StringBuilder();
		sb.append("order_id=" + order_id);
		sb.append(" order_date_begin=" + order_date_begin);
		sb.append(" order_date_end=" + order_date_end);
		sb.append(" refund_date_begin=" + refund_date_begin);
		sb.append(" refund_date_end=" + refund_date_end);
		sb.append(" search_word=" + search_word);
		sb.append(" order_stat=" + order_stat);
		sb.append(" isTip=" + isTip);
		sb.append(" sign=" + sign);
		logger.info("交易查询接口：" + sb);
		
		Map<String, Object> map=new HashMap<String, Object>();
		List<Map<String, Object>> allId = searchOrderServices.searchOrderIds(order_id, order_date_begin, order_date_end, refund_date_begin, refund_date_end, search_word, order_stat,isTip);
		logger.info("查到符合条件的数据"+allId.size()+"条");
		
		String key = null;
		if (allId.size() > 0) {
			key = DataBaseMap.createKey();
			SearchOrderIds searchOrderIds = new SearchOrderIds();
			searchOrderIds.setLastTime(System.currentTimeMillis());
			Map<String, Object> whereMap = new HashMap<String, Object>();
			whereMap.put("order_id", order_id);
			whereMap.put("order_date_begin", order_date_begin);
			whereMap.put("order_date_end", order_date_end);
			whereMap.put("refund_date_begin", refund_date_begin);
			whereMap.put("refund_date_end", refund_date_end);
			whereMap.put("search_word", search_word);
			whereMap.put("order_stat", order_stat);
			searchOrderIds.setWhereMap(whereMap);
			searchOrderIds.setAllId(allId );
			DataBaseMap.put(key, searchOrderIds );
		}

		map.put("resp_status", "0000");
		map.put("result_id", key);
		map.put("result_quantity", ""+allId.size());
		map.put("sign", "transSystem_searchOrder_sign");
		return map;

	}
}
